package com.fancy.learncenter.ui.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.fancy.learncenter.R;
import com.fancy.learncenter.ui.callback.AlbumImpl;
import com.fancy.learncenter.ui.view.ZoomableDraweeView;
import com.fancy.learncenter.utils.ImgFilter;
import com.fancy.learncenter.utils.Utils;

import java.util.List;

/**
 * Created by admin on 2017/4/19.
 */

public class ViewPageAdapter extends PagerAdapter{


    Context context;
    List<String> stringList;
    AlbumImpl listener;
    public ViewPageAdapter(Context context, List<String> stringList, AlbumImpl listener) {

        this.context = context;
        this.stringList = stringList;
        this.listener = listener;
    }

    @Override
    public int getCount() {
        return stringList.size();
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {

        View view = LayoutInflater.from(context).inflate(R.layout.large_image_item, null);
        ZoomableDraweeView zoomableDraweeView = (ZoomableDraweeView) view.findViewById(R.id.zoom_view);
        zoomableDraweeView.setImageURI(Utils.getImgUri(stringList.get(position)));
        container.addView(view);

        zoomableDraweeView.setOnClickListener(new ZoomableDraweeView.OnClickListener() {
            @Override
            public void onClick() {

                if (listener != null){
                    listener.onClick(position);
                }
            }
        });

        return view;

    }
}
